package sg.edu.nus.dashboard.stat.control.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.rpc.IResponder;
	
	import sg.edu.nus.dashboard.main.model.AppModelLocator;
	import sg.edu.nus.dashboard.stat.control.business.GetStatDelegate;
	import sg.edu.nus.dashboard.stat.control.event.GetStatEvent;
	import sg.edu.nus.dashboard.util.StatUtil;
	
	public class GetStatCommand implements ICommand, IResponder
	{
		private var model:AppModelLocator = AppModelLocator.getInstance();
		
		public function execute(event:CairngormEvent):void
		{
			var d:GetStatDelegate = new GetStatDelegate(this);
			var e:GetStatEvent = GetStatEvent(event);
			
			d.getStatByName(e.paraName, e.fromTime, e.toTime);
		}
		
		public function result(data:Object):void
		{
			model.stat.statRawArr = data.result;
			StatUtil.getCurrentHealthRatio();
			StatUtil.filterStat();
			StatUtil.getPieStat();
		}
		
		public function fault(info:Object):void
		{
			
		}
	}
}